import Cookies from 'js-cookie'
import { DEVICE } from "@/global/const";
export const useAppStore = defineStore(
  'app',
  () => {
    const device = ref<DEVICE>(DEVICE.desktop);

    const sidebar = ref({
      opened: localStorage.getItem('sidebarStatus') ? !!+localStorage.getItem('sidebarStatus') : true,
      hide: false
    })

    const size = ref(Cookies.get('size') || 'default');

    /**
     * device 左侧菜单宽度切换
     * @param device
     */
    const toggleDevice = (deviceVal: DEVICE) => {
      device.value = deviceVal
    }

    /**
     * 切换 SideBar 形态
     */
    const toggleSideBar = () => {
      sidebar.value.opened = !sidebar.value.opened;
    }

    const setSize = (sizeStr: string) => {
      size.value = sizeStr;
      Cookies.set('size', sizeStr)
    }

    const toggleSideBarHide = (status: boolean) => {
      sidebar.value.hide = status
    }

    return {
      device,
      sidebar,
      size,
      toggleDevice,
      toggleSideBar,
      setSize,
      toggleSideBarHide,

    }
  }
)